import '../public/index'
import store from 'store'

let data = new Vue({
  el: '#data',
  data: () => ({
    name          : '',
    developerName : '',
    propertyName  : '',
    type          : 1,
    typeName      : '',
    price         : 0,
    equalMoney    : 0
  }),
  watch: {
    type: function(val, oldVal) {
      switch (this.type - 0) {
        case 0:
          this.typeName = '商务类'
          break
        case 1:
          this.typeName = '住宅类'
          break
      }
    }
  },
  mounted: function() {
    let storeData = store.get('storeData')

    console.log(storeData)

    if (!storeData) {
      layer.msg('页面跳转错误', {
        icon: 5
      })

      setTimeout(() => {
        window.location = './index.html'
      }, 1000)

      return
    }

    storeData.equalMoney = showNum(storeData.equalMoney)
    storeData.price = showNum(storeData.price)
    // 合并数据
    $.extend(this.$data, storeData)
  }
})




//在这里处理storeData里边的equalMoney字段和price字段
function showNum(num) {
  let numStr = (num / 100).toFixed(2)
  // console.log(numStr)
  const pointIndex = numStr.indexOf('.')

  let lastNum = numStr[pointIndex + 1] + numStr[pointIndex + 2]
  // console.log('lastNum===>', lastNum)
  if (lastNum == 0) { //没有角没有分
    return (num / 100).toFixed(0)
  } else if (lastNum[1] == 0 && lastNum[0] > 0) { //有角没有分  100.01
    return (num / 100).toFixed(1)
  } else { //有角有分或者 没有角有分
    return numStr
  }
}